<template>
  <HeadTail></HeadTail>
  <div class="box">
    <div class="box-text left" @click="add">
      商家名称：{{ order.name }}
    </div>
    <div class="box-img left">
      <img :src="img" alt="" />
    </div>
    <div class="box-name">商品名称：{{ order.productName }}</div>
    <div class="box-a left">
      <p class="box-price-p1">配送地址:</p>
      <p class="box-price-p1">{{ address }}</p>
    </div>
    <div class="box-b left">
      <p class="box-price-p1">配送时间:</p>
      <p class="box-price-p1">{{ orderTime }}</p>
    </div>
    <div class="box-c left">
      <p class="box-price-p1">合计价格:</p>
      <p class="box-price-p1">￥{{ price }}</p>
    </div>
    <div class="">
      <button class="box-but -ml-[75%]" @click="getStore">收藏</button>
    </div>
    <div class="box-cg">下单成功<br/>请注意查收！</div>
    <button class="box-but" @click="tohome">返回首页</button>
  </div>
</template>
<script setup>
import { reactive, ref, onMounted, computed } from "vue";
import { useRoute } from "vue-router";
import { useRouter } from "vue-router";
import HeadTail from "@/components/Nhome/HeadTail.vue";
import axios from "axios";
const route = useRoute();
const router = useRouter();
const list = ref();
let price = ref();
let time = ref();
let order = ref([]);
let img = ref([])
let address=ref()
onMounted(() => {
  price.value = route.query.totalprice;
  time.value = route.query.ordertime;
  order.value = JSON.parse(route.query.shopdata);
  img.value = order.value.img.split(',')[1]
  address.value = JSON.parse(route.query.orderaddress) 
  list.value = route.query.userstoreid
  console.log(order.value.productId);
});
let orderTime = computed(() => {
  let date = new Date(parseInt(time.value));
  let Year = date.getFullYear();
  let Moth =date.getMonth() + 1 < 10? "0" + (date.getMonth() + 1): date.getMonth() + 1;
  let Day = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
  let Hour = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
  let Minute =date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
  let Sechond =date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
  let GMT =Year + "-" + Moth + "-" + Day + "   " + Hour + ":" + Minute + ":" + Sechond;
  return GMT
});
function tohome() {
  router.push('Nhome')
}
function getStore() {
  axios.post(`http://1.14.126.98:8081/star/staradd?userId=${list.value}&productId=${order.value.productId}`).then((res) => {
    alert(res.data.msg)
    console.log(res.data);
  })
}
</script>
<style lang="scss" scoped>
@import "@/components/zhouq/orderCompletion/index.scss";
</style>
